<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>课程分类管理</title>

    <link rel="stylesheet" href="__STATIC__/admin/js/layer/theme/default/layer.css">
    <link rel="stylesheet" href="__STATIC__/admin/js/layui/css/layui.css">
    <link rel="stylesheet" href="__STATIC__/admin/js/bootstrap/css/bootstrap.css">

    <script src="__STATIC__/admin/js/jquery.min.js"></script>
    <script src="__STATIC__/admin/js/layer/layer.js"></script>
    <script src="__STATIC__/admin/js/layui/layui.js"></script>
    <script src="__STATIC__/admin/js/bootstrap/js/bootstrap.js"></script>

</head>
<body>
<table class="table table-hover">
    <thead>
    <tr>
        <th>编号</th>
        <th>课程分类</th>
        <th>是否删除</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody>
    {volist name="Courseclassify" id="v"}
    <tr>
        <td>{$v.classify_id}</td>
        <td>{$v.course_classify}</td>
        <td>{if condition="$v.classify_del eq '1'"}删除{else /}显示{/if}</td>

        <td>
            {if condition="$v.classify_del eq '1'"}
            <!--<button class="button_1 layui-btn layui-btn-normal" data-id="{$v.classify_id}" data-ifid="1" >显示</button>-->
            <button class="button_1 layui-btn layui-btn-normal layui-btn-radius" data-id="{$v.classify_id}" data-ifid="1" >显示</button>
            {else /}
            <!--<button class="button_2 layui-btn layui-btn-normal" data-id="{$v.classify_id}" data-ifid="2">不显示</button>-->
            <button class="button_1 layui-btn layui-btn-radius" data-id="{$v.classify_id}" data-ifid="2" >不显示</button>

            {/if}
            <button class="button_1 layui-btn layui-btn-danger" data-id="{$v.classify_id}" data-ifid="3"><i class="layui-icon"></i>删除</button>
        </td>
    </tr>
    {/volist}
    </tbody>
    <button class="button_2 layui-btn layui-btn-normal"><i class="layui-icon"></i>新增</button>
</table>


</body>
<script>

    //删除jquery
    $(document).ready(function(){
        $('.button_1').click(function () {

            var link = $(this);
            var courses = link.attr("data-id");
            var dataid = link.attr("data-ifid");

            if(dataid == 3){
                if(!confirm("确定删除吗")){
                    return false;
                }
            }

            layer.load();
            setTimeout(function () {
                layer.closeAll('loading');
            }, 2000);

            $.get("{:url('admin/Courseclassify/delete')}?id=" + courses+"&dataifid="+dataid, function (data) {

                if(data>0){
                    layer.msg('删除成功', {icon: 1});
                    window.location.href = ("{:url('admin/Courseclassify/index')}");

                }else {
                    layer.msg('删除失败', {icon: 2});
                }
            })
        })


        //弹出一个页面层
        $('.button_2').on('click', function(){
            layer.open({
                type: 1,
                area: ['600px', '360px'],
                shadeClose: true, //点击遮罩关闭
                content: content()
            });
        });

    })

    //弹窗html
    function content() {
        var code = '<div style=\'padding:20px; width: 500px; height: 300px\'>' +
            "<table><tr><th>课程分类</th><td><input type=\"text\" class=\"course_classify\" name=\"course_classify\" value=\"\"></td></tr></table>" +
            "<button class=\"button_3 layui-btn layui-btn-normal\" style=\"margin-top: 10px\"><i class=\"layui-icon\"></i>新增</button>" +
            "</div>" +
            "<script>\n" +
            "    $(document).ready(function(){\n" +
            "        $('.button_3').click(function () {\n" +
            "            var data = {};\n" +
            "            data.course_classify = $(\".course_classify\").val();\n" +
            "            if(data.course_classify == \"\"){\n" +
            "                layer.tips('*:ஐ٩(๑´ᵕ`)۶ஐ:*不能为空哦', '.button_3');\n" +
            "                return false;\n" +
            "            }\n" +
            "            $.post(\"{:url('admin/Courseclassify/classifyInsert')}\",data,function (data) {\n" +
            "                var josn = JSON.parse( data );\n" +
            "                if(josn > 0){\n" +
            "                    layer.msg('(:3[▓▓]快醒醒开学了', {icon: 1});\n" +
            "                    setTimeout(function(){\n" +
            "                        window.location.href = (\"{:url('admin/Courseclassify/index')}\");\n" +
            "                    }, 2000);\n" +
            "                }else {\n" +
            "                    layer.msg('￣へ￣ 失败了！！', {icon: 2});\n" +
            "                }\n" +
            "            })\n" +
            "        })\n" +
            "    })\n" +
            "<\/script>";
        return code;
    }

</script>


</html>